import java.sql.*;

public class DBUtil {
  private Connection connection;
  private Statement statement;
  private static String tableName;

  public DBUtil (String tablename) {
    tableName = tablename;
  }

  public boolean setConnection(String path) {
    try {
      Class.forName("org.sqlite.JDBC");
      this.connection = DriverManager.getConnection(path);

      statement = this.connection.createStatement();
//      statement.setQueryTimeout(30);

      statement.executeUpdate(
            "CREATE TABLE " +
                    tableName +
                  " (cycle INTEGER ," +
                  " playMode TEXT ," +
                  " object TEXT ," +
                  " type TEXT ," +
                  " posX DOUBLE ," +
                  " posY DOUBLE ," +
                  " vecX DOUBLE ," +
                  " vecY DOUBLE ," +
                  " bodyDir DOUBLE ," +
                  " neckDir DOUBLE ," +
//                  " visionType VARCHAR ," +
//                  " visionRange DOUBLE ," +
                  " stamina DOUBLE ," +
                  " focusObject TEXT ," +
                  " actions TEXT );");
    } catch (SQLException e) {
      return false;
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    return true;
  }

  public void excute(String sql) {
    try {
      this.statement.executeUpdate(sql);
    } catch (SQLException throwables) {
      System.out.println(sql);
      throwables.printStackTrace();
    }
  }

  public void endConnection() {
    try {
      connection.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
